

%% load estimation results
load('decade_initial_replication.mat')
[~,use] = min(l0);
thetaStar = theta(:,use);
clearvars -except thetaStar K mpow N reb X Y YY Z specif


%% load everything of interest
load('../../baseline_model/sim_eq_round2.mat')
load('data_decade_initial.mat','nmissing')
U0=repmat(U0,1,1,5);
intEq=cell(NS/5,N*5);
VR=zeros(size(V_R,1),NS/5,N*5);
VUS=VR;
VUK=VR;
VFrance=VR;
VRussia=VR;
VChina=VR;
for t=1:5
    intEq(:,N*(t-1)+(1:N))=intervEq(NS/5*(t-1)+(1:NS/5),:);
    VR(:,:,N*(t-1)+(1:N))=V_R(:,NS/5*(t-1)+(1:NS/5),:);
    VUS(:,:,N*(t-1)+(1:N))=V_US(:,NS/5*(t-1)+(1:NS/5),:);
    VUK(:,:,N*(t-1)+(1:N))=V_UK(:,NS/5*(t-1)+(1:NS/5),:);
    VFrance(:,:,N*(t-1)+(1:N))=V_France(:,NS/5*(t-1)+(1:NS/5),:);
    VRussia(:,:,N*(t-1)+(1:N))=V_Russia(:,NS/5*(t-1)+(1:NS/5),:);
    VChina(:,:,N*(t-1)+(1:N))=V_China(:,NS/5*(t-1)+(1:NS/5),:);
end
U0=U0(:,:,nmissing);
intervEq=intEq(:,nmissing);
V_R=VR(:,:,nmissing);
V_US=VUS(:,:,nmissing);
V_UK=VUK(:,:,nmissing);
V_France=VFrance(:,:,nmissing);
V_Russia=VRussia(:,:,nmissing);
V_China=VChina(:,:,nmissing);
clear t intEq VR VUS VUK VFrance VRussia VChina
[DMES,intervEq] = createDMES(intervEq,V_R,V_US,V_UK,V_France,V_Russia,V_China,YY,specif);


%% standard errors via Hessian
InvSigmaH = HessPhat(thetaStar,1,Y,X,Z,YY,V_R,V_US,V_UK,V_France,V_Russia,V_China,U0,intervEq,DMES,reb,mpow);
seH = sqrt(diag(inv(InvSigmaH)));
resultsH = printResults([thetaStar,seH,2*normcdf(abs(thetaStar./seH),'upper')],reb,mpow,specif);
disp(' ')
disp('for Tables E9-E10:')
disp(resultsH)


%%
clearvars -except thetaStar InvSigmaH seH resultsH 
save('inference_decade_initial.mat')



